﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Controller;

namespace QLKS
{
    public partial class FrmCheckRoom1 : Form
    {
        Controller_Room cont_room = new Controller_Room();
        public FrmCheckRoom1()
        {
            InitializeComponent();
        }


        private void FrmCheckRoom1_Load(object sender, EventArgs e)
        {
            doDateNow();
            GetStatusRoom();
        }

        private void GetStatusRoom()
        {
            int thang = int.Parse(cmbThang.Text.ToString());
            int ngay = int.Parse(cmbNgay.Text.ToString());  
            int nam = int.Parse(cmbNam.Text.ToString());
            DataTable dt = cont_room.RoomStatus(ngay, thang, nam).Tables[0];

            #region hiển thị trạng thái phòng
            //Khu Ven Sông
            if (dt.Rows[0]["Trangthai"].ToString() == "1") btnA1.BackColor = System.Drawing.Color.Red;
                else btnA1.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[1]["Trangthai"].ToString() == "1") btnA2.BackColor = System.Drawing.Color.Red;
                else btnA2.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[2]["Trangthai"].ToString() == "1") btnA3.BackColor = System.Drawing.Color.Red;
                else btnA3.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[3]["Trangthai"].ToString() == "1") btnA4.BackColor = System.Drawing.Color.Red;
                else btnA4.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[4]["Trangthai"].ToString() == "1") btnA5.BackColor = System.Drawing.Color.Red;
                else btnA5.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[5]["Trangthai"].ToString() == "1") btnA6.BackColor = System.Drawing.Color.Red;
                else btnA6.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[6]["Trangthai"].ToString() == "1") btnA7.BackColor = System.Drawing.Color.Red;
                else btnA7.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[7]["Trangthai"].ToString() == "1") btnA8.BackColor = System.Drawing.Color.Red;
                else btnA8.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[8]["Trangthai"].ToString() == "1") btnA9.BackColor = System.Drawing.Color.Red;
                else btnA9.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[9]["Trangthai"].ToString() == "1") btnA10.BackColor = System.Drawing.Color.Red;
                else btnA10.BackColor = System.Drawing.Color.PaleGreen;


            if (dt.Rows[10]["Trangthai"].ToString() == "1") btnB1.BackColor = System.Drawing.Color.Red;
            else btnB1.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[11]["Trangthai"].ToString() == "1") btnB2.BackColor = System.Drawing.Color.Red;
            else btnB2.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[12]["Trangthai"].ToString() == "1") btnB3.BackColor = System.Drawing.Color.Red;
            else btnB3.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[13]["Trangthai"].ToString() == "1") btnB4.BackColor = System.Drawing.Color.Red;
            else btnB4.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[14]["Trangthai"].ToString() == "1") btnB5.BackColor = System.Drawing.Color.Red;
            else btnB5.BackColor = System.Drawing.Color.PaleGreen;

            if (dt.Rows[15]["Trangthai"].ToString() == "1") btnC1.BackColor = System.Drawing.Color.Red;
                else btnC1.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[16]["Trangthai"].ToString() == "1") btnC2.BackColor = System.Drawing.Color.Red;
                else btnC2.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[17]["Trangthai"].ToString() == "1") btnC3.BackColor = System.Drawing.Color.Red;
                else btnC3.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[18]["Trangthai"].ToString() == "1") btnC4.BackColor = System.Drawing.Color.Red;
                else btnC4.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[19]["Trangthai"].ToString() == "1") btnC5.BackColor = System.Drawing.Color.Red;
                else btnC5.BackColor = System.Drawing.Color.PaleGreen;

            //Khu làng mộc
            if (dt.Rows[20]["Trangthai"].ToString() == "1") btn1A.BackColor = System.Drawing.Color.Red;
                else btn1A.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[21]["Trangthai"].ToString() == "1") btn1B.BackColor = System.Drawing.Color.Red;
                else btn1B.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[22]["Trangthai"].ToString() == "1") btn2A.BackColor = System.Drawing.Color.Red;
                else btn2A.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[23]["Trangthai"].ToString() == "1") btn2B.BackColor = System.Drawing.Color.Red;
                else btn2B.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[24]["Trangthai"].ToString() == "1") btn3A.BackColor = System.Drawing.Color.Red;
                else btn3A.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[25]["Trangthai"].ToString() == "1") btn3B.BackColor = System.Drawing.Color.Red;
                else btn3B.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[26]["Trangthai"].ToString() == "1") btn4A.BackColor = System.Drawing.Color.Red;
                else btn4A.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[27]["Trangthai"].ToString() == "1") btn4B.BackColor = System.Drawing.Color.Red;
                else btn4B.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[28]["Trangthai"].ToString() == "1") btn5A.BackColor = System.Drawing.Color.Red;
                else btn5A.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[29]["Trangthai"].ToString() == "1") btn5B.BackColor = System.Drawing.Color.Red;
                else btn5B.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[30]["Trangthai"].ToString() == "1") btn6A.BackColor = System.Drawing.Color.Red;
                else btn6A.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[31]["Trangthai"].ToString() == "1") btn6B.BackColor = System.Drawing.Color.Red;
                else btn6B.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[32]["Trangthai"].ToString() == "1") btn7A.BackColor = System.Drawing.Color.Red;
                else btn7A.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[33]["Trangthai"].ToString() == "1") btn7B.BackColor = System.Drawing.Color.Red;
                else btn7B.BackColor = System.Drawing.Color.PaleGreen;

            //Làng Tây Nguyên
            if (dt.Rows[34]["Trangthai"].ToString() == "1") btnTN1.BackColor = System.Drawing.Color.Red;
                 else btnTN1.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[35]["Trangthai"].ToString() == "1") btnTN2.BackColor = System.Drawing.Color.Red;
                else btnTN2.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[36]["Trangthai"].ToString() == "1") btnTN3.BackColor = System.Drawing.Color.Red;
                else btnTN3.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[37]["Trangthai"].ToString() == "1") btnTN4.BackColor = System.Drawing.Color.Red;
                else btnTN4.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[38]["Trangthai"].ToString() == "1") btnTN5.BackColor = System.Drawing.Color.Red;
                else btnTN5.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[39]["Trangthai"].ToString() == "1") btnTN6.BackColor = System.Drawing.Color.Red;
                else btnTN6.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[40]["Trangthai"].ToString() == "1") btnTN7.BackColor = System.Drawing.Color.Red;
                else btnTN7.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[41]["Trangthai"].ToString() == "1") btnTn8.BackColor = System.Drawing.Color.Red;
                 else btnTn8.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[42]["Trangthai"].ToString() == "1") btnTN9.BackColor = System.Drawing.Color.Red;
                else btnTN9.BackColor = System.Drawing.Color.PaleGreen;
            if (dt.Rows[43]["Trangthai"].ToString() == "1") btnTN11.BackColor = System.Drawing.Color.Red;
                else btnTN11.BackColor = System.Drawing.Color.PaleGreen;

            #endregion

        }

        private void btnCheck_Click(object sender, EventArgs e)
        {
            GetStatusRoom();
        }

        private void cmbNgay_DropDownClosed(object sender, EventArgs e)
        {
            GetStatusRoom();
        }

        private void cmbThang_DropDownClosed(object sender, EventArgs e)
        {
            cmbThang_SelectedIndexChanged(sender, e);
            GetStatusRoom();
        }

        private void cmbNam_DropDownClosed(object sender, EventArgs e)
        {
            cmbThang_SelectedIndexChanged(sender, e);
            GetStatusRoom();
        }

        private void cmbThang_SelectedIndexChanged(object sender, EventArgs e)
        {
            int thang = int.Parse(cmbThang.Text.ToString());
            int nam = int.Parse(cmbNam.Text.ToString());
            cmbNgay.Items.Clear();
            if (thang == 1 || thang == 3 || thang == 5 || thang == 7 || thang == 8 || thang == 10 || thang == 12)
                this.cmbNgay.Items.AddRange(new object[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" });
            else if (thang == 4 || thang == 6 || thang == 9 || thang == 11)
                this.cmbNgay.Items.AddRange(new object[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30" });
            else if (nam % 100 != 0 && nam % 4 == 0)
                this.cmbNgay.Items.AddRange(new object[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29" });
            else
                this.cmbNgay.Items.AddRange(new object[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28" });
            
            if (DateTime.Now.Day <= cmbNgay.Items.Count)
            {
                cmbNgay.Text = DateTime.Now.Day.ToString();
            }
            else
                cmbNgay.SelectedIndex = 0;

        }

        private void btnDateNow_Click(object sender, EventArgs e)
        {
            doDateNow();
            GetStatusRoom();
        }

        private void doDateNow()
        {
            cmbNgay.Text = DateTime.Now.Day.ToString();
            cmbNam.Text = DateTime.Now.Year.ToString();
            cmbThang.Text = DateTime.Now.Month.ToString();
            int nam = int.Parse(cmbNam.Text.ToString());
            int thang = int.Parse(cmbThang.Text.ToString());
            cmbNgay.Items.Clear();
            if (thang == 1 || thang == 3 || thang == 5 || thang == 7 || thang == 8 || thang == 10 || thang == 12)
                this.cmbNgay.Items.AddRange(new object[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" });
            else if (thang == 4 || thang == 6 || thang == 9 || thang == 11)
                this.cmbNgay.Items.AddRange(new object[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30" });
            else if (nam % 100 != 0 && nam % 4 == 0)
                this.cmbNgay.Items.AddRange(new object[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29" });
            else
                this.cmbNgay.Items.AddRange(new object[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28" });
            cmbNgay.Text = DateTime.Now.Day.ToString();
        }

        #region các hàm chọn phòng để đăng kí

        public void doShowCheckIn(string maPhong)
        {
            int thang = int.Parse(cmbThang.Text.ToString());
            int ngay = int.Parse(cmbNgay.Text.ToString());
            int nam = int.Parse(cmbNam.Text.ToString());
            FrmCheckRoom obj = (FrmCheckRoom)this.ParentForm;
            obj.showRoom(ngay, thang, nam, maPhong);

        }

        private void btn7B_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            if (btn.BackColor == System.Drawing.Color.Red)
            {
                MessageBox.Show("Phòng này đã có người đặt!", "Thông báo",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                return;
            }
            if (btn.Name == "btnA1")
                doShowCheckIn("01");
            else if (btn.Name == "btnA2")
                doShowCheckIn("02");
            else if (btn.Name == "btnA3")
                doShowCheckIn("03");
            else if (btn.Name == "btnA4")
                doShowCheckIn("04");
            else if (btn.Name == "btnA5")
                doShowCheckIn("05");
            else if (btn.Name == "btnA6")
                doShowCheckIn("06");
            else if (btn.Name == "btnA7")
                doShowCheckIn("07");
            else if (btn.Name == "btnA8")
                doShowCheckIn("08");
            else if (btn.Name == "btnA9")
                doShowCheckIn("09");
            else if (btn.Name == "btnA10")
                doShowCheckIn("10");

            else if (btn.Name == "btnB1")
                doShowCheckIn("11");
            else if (btn.Name == "btnB2")
                doShowCheckIn("12");
            else if (btn.Name == "btnB3")
                doShowCheckIn("13");
            else if (btn.Name == "btnB4")
                doShowCheckIn("14");
            else if (btn.Name == "btnB5")
                doShowCheckIn("15");
            else if (btn.Name == "btnC1")
                doShowCheckIn("16");
            else if (btn.Name == "btnC2")
                doShowCheckIn("17");
            else if (btn.Name == "btnC3")
                doShowCheckIn("18");
            else if (btn.Name == "btnC4")
                doShowCheckIn("19");
            else if (btn.Name == "btnC5")
                doShowCheckIn("20");

            else if (btn.Name == "btn1A")
                doShowCheckIn("21");
            else if (btn.Name == "btn1B")
                doShowCheckIn("22");
            else if (btn.Name == "btn2A")
                doShowCheckIn("23");
            else if (btn.Name == "btn2B")
                doShowCheckIn("24");
            else if (btn.Name == "btn3A")
                doShowCheckIn("25");
            else if (btn.Name == "btn3B")
                doShowCheckIn("26");
            else if (btn.Name == "btn4A")
                doShowCheckIn("27");
            else if (btn.Name == "btn4B")
                doShowCheckIn("28");
            else if (btn.Name == "btn5A")
                doShowCheckIn("29");
            else if (btn.Name == "btn5B")
                doShowCheckIn("30");
            else if (btn.Name == "btn6A")
                doShowCheckIn("31");
            else if (btn.Name == "btn6B")
                doShowCheckIn("32");
            else if (btn.Name == "btn7A")
                doShowCheckIn("33");
            else if (btn.Name == "btn7B")
                doShowCheckIn("34");

            else if (btn.Name == "btnTN1")
                doShowCheckIn("35");
            else if (btn.Name == "btnTN2")
                doShowCheckIn("36");
            else if (btn.Name == "btnTN3")
                doShowCheckIn("37");
            else if (btn.Name == "btnTN4")
                doShowCheckIn("38");
            else if (btn.Name == "btnTN5")
                doShowCheckIn("39");
            else if (btn.Name == "btnTN6")
                doShowCheckIn("40");
            else if (btn.Name == "btnTN7")
                doShowCheckIn("41");
            else if (btn.Name == "btnTn8")
                doShowCheckIn("42");
            else if (btn.Name == "btnTN9")
                doShowCheckIn("43");
            else if (btn.Name == "btnTN11")
                doShowCheckIn("44");

        }
        #endregion
    }
}
